window.onload=function ()
{
    var vue = new Vue({
        el:"#app",
        data:{
            entityList:[],
            searchEntity:{auditStatus:'0'},
            status:['未审核','审核中','审核未通过','已关闭'],
            ids:[],
            checked:false,
            pages:0,
            current:1
        },
        methods:{
            findByPage:function (current)
            {
                axios.get("/goods/findByPage?page="+current,{params:this.searchEntity}).then(function (response)
                {
                    vue.entityList=response.data.rows;
                    vue.pages=response.data.pages;
                    vue.current=current;
                })
            },
            vueFindByPage:function ()
            {
                this.current=(vue.current==vue.pages && this.checked) ? vue.current-1 : vue.current;
                this.current=(vue.current == 0) ? 1 : vue.current;
                this.findByPage(vue.current);
                this.ids=[];
            },
            updateAuditStatus:function (auditStatus)
            {
                if(this.ids.length>0)
                {
                    axios.get("/goods/updateStatus?ids="+this.ids+"&auditStatus="+auditStatus).then(function (response)
                    {
                        if(response.data)
                        {
                            //重新查找
                            vue.vueFindByPage();
                        }
                        else
                        {
                            alert("操作失败！");
                        }
                    })
                }
                else
                {
                    alert("请选择要操作的商品");
                }
            },
            del:function ()
            {
                /*实现逻辑删除*/
                if(this.ids.length>0)
                {
                    axios.get("/goods/updateStatus?ids="+this.ids).then(function (response)
                    {
                        if (response.data)
                        {
                            //重新查找
                            vue.vueFindByPage();
                        }
                        else
                        {
                            alert("删除失败！")
                        }
                    })
                }
                else
                {
                    alert("请选择要删除的商品");
                }
            },
            checkAll:function (event)
            {
                this.ids=[];
                if(event.target.checked)
                {
                    for(var i=0; i<this.entityList.length; i++)
                    {
                        this.ids.push(this.entityList[i].id);
                    }
                }
            }
        },
        updated:function ()
        {
            this.checked=(this.ids.length==this.entityList.length);
        },
        created:function ()
        {
            this.findByPage(this.current);
        }
    })
};